# 使用官方的.NET 8 SDK镜像作为构建环境
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env
WORKDIR /app

# 复制项目文件并还原依赖
COPY *.sln ./
COPY CoreManager.API/*.csproj ./CoreManager.API/
COPY CoreManager.Core/*.csproj ./CoreManager.Core/
COPY CoreManager.Repository/*.csproj ./CoreManager.Repository/
COPY CoreManager.Models/*.csproj ./CoreManager.Models/
COPY CoreManager.Services/*.csproj ./CoreManager.Services/

RUN dotnet restore

# 复制所有文件并构建应用
COPY . ./
RUN dotnet publish CoreManager.API -c Release -o out

# 使用官方的ASP.NET Core运行时镜像
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app

# 安装中文字体和时区数据
RUN apt-get update && apt-get install -y \
    locales \
    tzdata \
    && rm -rf /var/lib/apt/lists/*

# 设置时区
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# 设置中文环境
RUN sed -i '/zh_CN.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
ENV LANG zh_CN.UTF-8
ENV LANGUAGE zh_CN:zh
ENV LC_ALL zh_CN.UTF-8

# 复制构建输出
COPY --from=build-env /app/out .

# 创建日志目录
RUN mkdir -p /app/logs

# 暴露端口
EXPOSE 80

# 启动应用
ENTRYPOINT ["dotnet", "CoreManager.API.dll"]